<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
include("../navigation.php");
$GLOBALS["linkzusatz"]="";
if(isset($_GET["mouseover"])) {
	$GLOBALS["linkzusatz"].="&amp;mouseover=". $_GET["mouseover"];
} else {
	$GLOBALS["linkzusatz"].="&amp;mouseover=0";
}


if (!empty($_POST)) {
	if(!empty($_GET["dir"]) || (isset($_GET["dir"]) && $_GET["dir"]==0)) {
    	if ($_GET["dir"]==0) {
    		$row_act->id=0;
    		$row_act->name="/";
    	} else {
    		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation WHERE id='". $_GET["dir"] ."'");
    		if (mysql_num_rows($act_dir)==1) {
    			$row_act=mysql_fetch_object($act_dir);
    			if (!Contents::presence_rights($row_act->presence)) {
    				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
    			}
    			$GLOBALS["linkzusatz"].="&dir=". $row_act->id;
    		} else {
    			die("Da ist irgendwas schief gelaufen.");
    		}
    	}
    	if (!empty($_POST["filename"])) {
    		$field="graphic";
    		if (isset($_GET["mouseover"]) && $_GET["mouseover"]=="1") {
    			$field="overgraphic";
    		}
    		if (mysql_query("UPDATE ". $GLOBALS["db_pref"] ."navigation SET ". $field ."='". $_POST["filename"] ."' WHERE id='". $row_act->id ."'")) {
    			header("Location:admin_navigation_overview.php?dir=". $row_act->id);
    			exit();
    		}
    	}
	}
}

echo "<"."?xml version=\"1.0\"?".">";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    function submitImageForm(filename) {
    	document.forms[0].elements["filename"].value=filename;
    	document.forms[0].submit();
    }
    // -->
    </script>
  </head>
  <body id="editgrey">
    <?php
    $GLOBALS["linkzusatz"]="";
	if(isset($_GET["mouseover"])) {
		$GLOBALS["linkzusatz"].="&amp;mouseover=". $_GET["mouseover"];
	} else {
		$GLOBALS["linkzusatz"].="&amp;mouseover=0";
	}

    if(!empty($_GET["dir"]) || (isset($_GET["dir"]) && $_GET["dir"]==0)) {
    	if ($_GET["dir"]==0 && (isset($_GET["pres"]) && Contents::presence_rights($_GET["pres"]))) {
    		$row_act->id=0;
    		$row_act->presence=$_GET["pres"];
    		$row_act->name="/";
    	} else {
    		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation WHERE id='". $_GET["dir"] ."'");
    		if (mysql_num_rows($act_dir)==1) {
    			$row_act=mysql_fetch_object($act_dir);
    			if (!Contents::presence_rights($row_act->presence)) {
    				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
    			}
    			$GLOBALS["linkzusatz"].="&dir=". $row_act->id;
    		} else {
    			die("Da ist irgendwas schief gelaufen.");
    		}
    	}
    }
    ?>
   	<div id="overview">
   	  <h1>Navigationsgrafik</h1>
   	  <img src="images/dir_symbol.gif" width="64" height="64" alt="" style="padding-right:20px;float:left;" />
   	  <p>Belegen Sie einen Navigationspunkt mit einer Grafik.</p>
   	  <br style="clear:both;" />
    </div>
    <div id="edit">
    <table style="width:100%;padding:0px; margin:0px;border-top:0px;border-left:1px solid #aaaaaa;border-right:1px solid #aaaaaa;border-bottom:1px solid #aaaaaa; background-color:#ffffff" cellspacing="0" cellpadding="0">
      <tr>
        <th style="border:1px solid #666666;">W&auml;hlen Sie eine Grafik</th>
      </tr>
      <tr>
        <td style="padding:10px;" class="tdnormal">
      		<form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
      			<input type="hidden" name="filename" value=""/>
    			<?php
    			list_media($row_act->presence, 1);
    			echo "<br />";
   				?>
	   		</form>
        </td>
      </tr>
    </table>
    </div>
  </body>
</html>